package com.spzx.test2;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Test2 {
    public static void main(String[] args) {
        ArrayBlockingQueue<Integer> blockingQueue = new ArrayBlockingQueue<>(3);//阻塞队列
        new Thread(()->{
            int i = 0;
            while (true){
                i++;
                System.out.println("面包师做好第"+i+"个面包");
                try {
                    blockingQueue.put(i);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"面包师").start();
        new Thread(()->{
            int i = 0;
            while (true){
                i++;
                System.out.println("食客吃完"+i+"个面包");
                try {
                    blockingQueue.take();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"食客").start();


    }
}
